/**
* @author Zakaria DIALLO
*/

package sn.ugb.cours.zd.tools.shell;

import java.io.PrintStream;
import java.util.StringTokenizer;

public class EchoCommandImpl implements ShellCommand
{
    @SuppressWarnings("unused")
	private ShellContext context = null;

    public EchoCommandImpl(ShellContext context)
    {
        this.context = context;
    }

    public String getName()
    {
        return "echo";
    }

    public String getUsage()
    {
        return "\n echo <messages>                                      \n";
    }

    public String getShortDescription()
    {
        return "echo messages.                                            ";
    }

    public void execute(String cmdline, PrintStream out, PrintStream err)
    {
        StringTokenizer st = new StringTokenizer(cmdline, " ");

        // Ignore the command name.
        st.nextToken();

        // There should be at least one string.
        if (st.countTokens() >= 0)
        {
            while (st.hasMoreTokens())
            {
                out.print(st.nextToken().trim());
		out.print(' ');
            }
	    out.println();
        }
        else
        {
            err.println("Incorrect number of arguments");
        }
    }

}
